package com.bafa.front.admin;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;

import com.bafa.dbcache.LeagueCache;
import com.bafa.exceptions.ErrorException;
import com.bafa.front.DaddyServlet;
import com.bafa.objects.PageBean;
import com.bafa.services.RetrieveServices;
import com.bafa.services.SeasonServices;

public class AddTeamToSeasonServlet extends AdminServlet {

	@Override
	public void doAdminEvent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ErrorException {
		SeasonServices.addTeamToSeason(
				new Integer(request.getParameter("SeasonId")).intValue(),
				new Integer(request.getParameter("Division")).intValue(),
				new Integer(request.getParameter("TeamId")).intValue());
		HashMap teams = new HashMap();
		HttpSession session = request.getSession();
		if(session.getAttribute("ADDEDTEAMS")!=null){
			teams = (HashMap)session.getAttribute("ADDEDTEAMS");
		}
		request.setAttribute("CREATEDSEASON",RetrieveServices.getSeason(request.getParameter("SeasonId")));
		request.setAttribute("TEAMS",RetrieveServices.getAllTeams());
		teams.put(new Integer(request.getParameter("TeamId")).intValue(),new Integer(request.getParameter("Division")).intValue());
		session.setAttribute("ADDEDTEAMS", teams);
		PageBean pageBeanTemp = (PageBean)LeagueCache.getPages().get("createseason");
		pageBean = new PageBean(pageBeanTemp);
	}
}
